/*
 * blocking_queue.h
 */

#ifndef BLOCKING_QUEUE_H_
#define BLOCKING_QUEUE_H_

typedef void* data_t;
typedef struct node {
	struct node* next;
	data_t data;
} node_t;

typedef struct queue {
	node_t *head, *tail;
	long size;
	long max_size;
	int timeout;
	pthread_mutex_t mutex;
	pthread_cond_t consumed_cv;
	pthread_cond_t produced_cv;
} queue_t;


extern void queue_init(queue_t* queue, long max_size, int timeout);

/*
 * returns 0 in success and ETIMEDOUT when timeouted
 * */
extern int queue_put(queue_t* queue, data_t data);

/*
 * returns data or NULL when timeouted
 * */
extern data_t queue_get(queue_t* queue) ;

extern void queue_destroy(queue_t* queue);

#endif /* BLOCKING_QUEUE_H_ */
